﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using CameraViewer;

namespace MGHGame
{
    class WallArray
    {
        //an array of bounding boxes to store each wall
        BoundingBox []listOfWalls = new BoundingBox[7];


        public BoundingBox[] GetListOfWalls()
        {
            return listOfWalls;
        }

        public void InitializeWalls()
        {
            listOfWalls[0] = new BoundingBox(new Vector3(2.09f, 0.0f, -6.73f), 
                                             new Vector3(2.32f, 5.0f, -1.70f));

            listOfWalls[1] = new BoundingBox(new Vector3(2.12f, 0.0f, -0.18f), 
                                             new Vector3(7.12f, 5.0f,  0.03f));

            listOfWalls[2] = new BoundingBox(new Vector3(0.26f, 0.0f, -3.30f), 
                                             new Vector3(0.48f, 5.0f,  1.49f));

            listOfWalls[3] = new BoundingBox(new Vector3(-2.079f, 0.0f, -3.36f),
                                             new Vector3(-1.86f,  5.0f, -0.05f));
            
        }

        public void CheckWallCollisions(Camera cam)
        {
            // for each wall
            for (int i = 0; i < listOfWalls.Length; i++)
            {
                // first check to see if something hit the wall
                if (listOfWalls[i].Contains(cam.position) == ContainmentType.Contains)
                {
                    //if it hits the right part of the wall
                    if (cam.position.X >= (listOfWalls[i].Max.X - .03f) && cam.position.Z < listOfWalls[i].Max.Z && cam.position.Z > listOfWalls[i].Min.Z)
                    {
                        cam.position.X += .02f;
                        cam.view.X += .02f;
                    } // if it hits the left part of the wall
                    else if (cam.position.X <= (listOfWalls[i].Min.X + .03f) && cam.position.Z < listOfWalls[i].Max.Z && cam.position.Z > listOfWalls[i].Min.Z)
                    {
                        cam.position.X -= .02f;
                        cam.view.X -= .02f;
                    } // if it hits the rear part of the wall
                    else if(cam.position.Z >= (listOfWalls[i].Max.Z - .03f) && cam.position.X < listOfWalls[i].Max.X && cam.position.X > listOfWalls[i].Min.X)
                    {
                        cam.position.Z += .02f;
                        cam.view.Z += .02f;
                    } // if it hits the front part of the wall
                    else if (cam.position.Z <= (listOfWalls[i].Min.Z + .03f) && cam.position.X < listOfWalls[i].Max.X && cam.position.X > listOfWalls[i].Min.X)
                    {
                        cam.position.Z -= .02f;
                        cam.view.Z -= .02f;
                    }

                }
            }
        }
        // overloaded function to check for ghost collisions this time
        public void CheckWallCollisions(Vector3 position, Vector3 speed)
        {
            // for each wall
            for (int i = 0; i < listOfWalls.Length; i++)
            {
                // first check to see if something hit the wall
                if (listOfWalls[i].Contains(position) == ContainmentType.Contains)
                {
                    speed.X *= -1.0f;
                    speed.Z *= -1.0f;
                    /*//if it hits the right part of the wall
                    if (position.X >= (listOfWalls[i].Max.X - .03f) && position.Z < listOfWalls[i].Max.Z && position.Z > listOfWalls[i].Min.Z)
                    {
                        speed.X *= -1;
                        position.X += .02f;
                        
                    } // if it hits the left part of the wall
                    else if (position.X <= (listOfWalls[i].Min.X + .03f) && position.Z < listOfWalls[i].Max.Z && position.Z > listOfWalls[i].Min.Z)
                    {
                        speed.X *= -1;
                        position.X -= .02f;
                        
                    } // if it hits the rear part of the wall
                    else if (position.Z >= (listOfWalls[i].Max.Z - .03f) && position.X < listOfWalls[i].Max.X && position.X > listOfWalls[i].Min.X)
                    {
                        speed.Z *= -1;
                        position.Z -= .02f;

                    } // if it hits the front part of the wall
                    else if (position.Z <= (listOfWalls[i].Min.Z + .03f) && position.X < listOfWalls[i].Max.X && position.X > listOfWalls[i].Min.X)
                    {
                        speed.Z *= -1;
                        position.Z += .02f;
                    }*/

                }
            }
        }

        public void CheckWhichSide()
        {

        }
    }
}
